package cn.wolfcode.luowowo2.website.web.controller;

import cn.wolfcode.luowowo2.article.domain.StrategyCommend;
import cn.wolfcode.luowowo2.article.domain.Travel;
import cn.wolfcode.luowowo2.article.domain.TravelCommend;
import cn.wolfcode.luowowo2.article.service.IStrategyCommendService;
import cn.wolfcode.luowowo2.article.service.ITravelCommendService;
import cn.wolfcode.luowowo2.article.service.ITravelService;
import cn.wolfcode.luowowo2.common.query.TravelQueryObject;
import cn.wolfcode.luowowo2.member.domain.UserInfo;
import cn.wolfcode.luowowo2.website.web.annotation.RequireLogin;
import cn.wolfcode.luowowo2.website.web.annotation.UserParam;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Albert on 2019/7/6.
 */
@Controller
public class IndexController {
    @Reference
    private ITravelCommendService travelCommendService;

    @Reference
    private IStrategyCommendService strategyCommendService;

    @Reference
    private ITravelService travelService;

    @RequireLogin
    @RequestMapping("")
    public String goToMainPage(Model model){
        List<TravelCommend> tcs = travelCommendService.getTop5Commends();
        model.addAttribute("tcs",tcs);
        List<StrategyCommend> top5Commends = strategyCommendService.getTop5Commends();
        model.addAttribute("scs",top5Commends.subList(0,1));
        return "index/index";
    }

    @RequestMapping("/userInfo")
    @ResponseBody
    @RequireLogin
    public UserInfo getUserInfo(@UserParam UserInfo userInfo){
        return userInfo;
    }

    @RequestMapping("index/travelPage")
    public String travel(Model model,@ModelAttribute("qo") TravelQueryObject qo){
        PageInfo<Travel> pageInfo = travelService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "index/travelPageTpl";
    }
}
